//
//  UIBarButtonItem+Extensions.swift
//  ROM新浪微博
//
//  Created by 戴明亮 on 17/2/16.
//  Copyright © 2017年 戴明亮. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    // 遍历构造函数 便于进行条件判断 可返回可选项 必须使用 self.init 
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认 16号
    ///   - target: targer
    ///   - action: action
    ///   - isBack: isBack 是否是返回按钮 如果是加上箭头
    convenience  init(title: String, fontSize: CGFloat = 16, target: AnyObject, action: Selector,isBack: Bool = false) {
        
        
        
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        // self.init 实例化 uibarbuttonitem
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
             btn.setImage(UIImage.init(named: imageName), for: .normal)
             btn.setImage(UIImage.init(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        
        self.init(customView: btn)
        
    }
    
}
